﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XProject.DataVisit.Model.Doc;
using NHibernate.Criterion;
using NHibernate;
using NHibernate.Transform;
using XProject.DataVisit.Model.Temp;

namespace XProject.DataVisit.DAL.Doc
{
    public class DDocumentInfo : AbstractSupportDal<DocumentInfo>
    {
        public IList<DocumentInfo> GetSearchData(DocSearch c,Guid userid)
        {
            IList<DocumentInfo> t = new List<DocumentInfo>();
            Template.Execute(delegate(ISession session)
            {
                var k = session.CreateCriteria<DocumentInfo>();
                k.Add(Restrictions.Eq("UserID", userid));
                if (c.SearchName != null && c.SearchName != "")
                    k.Add(Restrictions.Or(Restrictions.Like("DocName", c.SearchName), Restrictions.Like("DocCustom", c.SearchName)));
                if (c.SearchType != null && c.SearchType != "")
                    k.Add(Restrictions.Eq("DocState", Convert.ToInt32(c.SearchType)));
                t = k.List<DocumentInfo>();
                return t;
            });
            return t;
        }

        public IList<DocumentInfo> GetSearchData()
        {
            IList<DocumentInfo> t = new List<DocumentInfo>();
            Template.Execute(delegate(ISession session)
            {
                var k = session.CreateCriteria<DocumentInfo>();
                    k.Add(Restrictions.Eq("DocState", 0));
                t = k.List<DocumentInfo>();
                return t;
            });
            return t;
        }

        public IList<DocumentInfo> GetSearchData_Susse(DocSearch c)
        {
            IList<DocumentInfo> t = new List<DocumentInfo>();
            Template.Execute(delegate(ISession session)
            {
                var k = session.CreateCriteria<DocumentInfo>();
                if (c.SearchName != null && c.SearchName != "")
                    k.Add(Restrictions.Or(Restrictions.Like("DocName", c.SearchName), Restrictions.Like("DocCustom", c.SearchName)));
                if (c.SearchType != null && c.SearchType != "")
                    k.Add(Restrictions.Eq("DocState", Convert.ToInt32(c.SearchType)));
                t = k.List<DocumentInfo>();
                return t;
            });
            return t;
        }

        /// <summary>
        /// 获取需要审核的申请单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IList<DocFlowTemp> GetSHList(Guid id)
        {
            IList<DocFlowTemp> t = new List<DocFlowTemp>();
            Template.Execute(delegate(ISession session)
            {
                t = session.GetNamedQuery("getMyDocFlow")
                    .SetGuid("id", id)
                    .SetResultTransformer(Transformers.AliasToBean<DocFlowTemp>())
                    .List<DocFlowTemp>();
                return t;
            });
            return t;
        }
    }
}
